<div id="mod_function_{{each_function.unique_id}}">
  <form id="mod_function_form" method="post" action="/function">
    {{form_conditional.csrf_token}}
    {{form_conditional.function_id(value=each_function.unique_id)}}
    {{form_conditional.function_type(value='function')}}

    <div class="row small-gutters" style="padding: 0.3em 0.2em 0.3em 0.3em;">
      <div class="col-auto">
        <button type="button" class="form-control btn btn-primary btn-sm btn-block" data-dismiss="modal">{{_('Close')}}</button>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).processRequest(this, 'function_mod');" name="function_mod" value="{{_('Save')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
      <div class="col-auto">
        <input onclick="return confirm('{{_('Are you sure you want to delete this?')}}') && $(this).processRequest(this, 'function_delete');" name="function_delete" value="{{_('Delete')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
      {% if each_function.function_type == 'function_actions' %}
      <div class="col-auto">
        <input onclick="return $(this).processRequest(this, 'execute_all_actions');" name="execute_all_actions" value="{{_('Execute All Actions')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
      {% endif %}
    </div>

    <div id="return_text_{{each_function.unique_id}}" class="col-12"></div>

  {% if each_function.function_type == 'function_actions' %}

    <div class="row small-gutters" style="padding: 0.5em">

      <div class="col-12">
        {{_("Name")}}: Execute Actions
      </div>

      <div class="col-12" style="padding-top: 0.3em">
        Sequentially execute all listed Actions.
      </div>

    </div>

    <div class="row small-gutters" style="padding: 0.3em 0.2em 0.3em 0.3em;">
      <div class="col-auto">
        {{form_function_base.name.label(class_='control-label')}}
        <div>
          {{form_function_base.name(class_='form-control', value=each_function.name, **{'title': dict_translation['name']['phrase']})}}
        </div>
      </div>
      <div class="col-auto">
        {{form_function_base.log_level_debug.label(class_='control-label')}}
        <div class="input-group-text">
          <input id="log_level_debug" name="log_level_debug" type="checkbox" title="{{dict_translation['log_level_debug']['phrase']}}" value="y"{% if each_function.log_level_debug %} checked{% endif %}>
        </div>
      </div>
    </div>

  </form>

  <form method="post" action="/function">
    {{form_actions.csrf_token}}
    {{form_actions.device_id(class_='form-control', value=each_function.unique_id)}}
    {{form_actions.function_type(class_='form-control', value='function')}}

    <div class="row align-items-end small-gutters" style="border-bottom: 1px solid #ddd; padding: 1.5em 0 0.2em 0.1em">
      <div class="col-auto">
        <select class="selectpicker" data-live-search="true" title="{{_('Action')}}: {{dict_translation['select_one']['title']}}" id="action_type_{{each_function.unique_id}}" name="action_type">
        {% for value, name in choices_actions %}
          <option value="{{value}}">{{name}}</option>
        {% endfor %}
        </select>
      </div>
      <div class="col-auto">
        <input onclick="return $(this).processRequest(this, 'add_action');" name="add_action" value="{{_('Add')}}" class="form-control btn btn-primary btn-sm btn-block" type="button"/>
      </div>
    </div>

  </form>

  {% set post_action = "/function" %}

  <div id="mod_function_actions_{{each_function.unique_id}}">
  {% for each_action in action if each_action.function_id == each_function.unique_id %}
    {% include 'pages/actions.html' %}
  {% endfor %}
  </div>

  {% endif %}

</div>
